
while getopts :e:t:i:u:p:h:w: opt
do
  case $opt in
  e) env="$OPTARG"; echo "ENV: $env";;
  t) tag="$OPTARG"; echo "TAG: $tag";;
  i) backend_image="$OPTARG"; echo "backend_image: $backend_image";;
  u) harbor_user="$OPTARG"; echo "harbor_user: $harbor_user";;
  p) harbor_password="$OPTARG"; echo "harbor_password: $harbor_password";;
  h) harbor_host="$OPTARG"; echo "harbor_host: $harbor_host";;
  w) ssh_web="$OPTARG"; echo "ssh_web: $ssh_web";;
  *) echo $opt not an option;;
  esac
done

export redis_image="harbor.pinlandata.com/pinlan/redis:latest"

echo -e "\e[1;36;5m======>Start deploy [$env] service...\e[0m"

pwd
whoami
ls -al

scp ./docker-compose.yml $ssh_web:/home/ai-ylt/config/

ssh -o StrictHostKeyChecking=no $ssh_web << remotessh

#----------------------------------------------

mkdir -p /home/ai-ylt/config
mkdir -p /home/ai-ylt/logs

cd /home/ai-ylt/config/

pwd
ls

docker login -u $harbor_user -p $harbor_password $harbor_host

export redis_image=$redis_image
echo "redis_image: $redis_image"

export backend_image=$backend_image
echo "backend_image: $backend_image"

export env=$env
echo "env: $env"

docker pull $redis_image
docker pull $backend_image

docker images

redis_image=$redis_image backend_image=$backend_image env=$env docker-compose down

redis_image=$redis_image backend_image=$backend_image env=$env docker-compose up -d


#----------------------------------------------
remotessh


echo -e "\e[1;32mService [$env] deploy success!\e[0m"
